package com.hq.talk.view.frg;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.hq.lib_comview.common.code.IntentKey;
import com.hq.talk.R;
import com.hq.talk.common.BaseEvent;
import com.hq.talk.common.Session;
import com.hq.talk.model.CommItemModel;
import com.hq.talk.view.base.BaseCommFrg;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 描述 ：消息界面
 * 作者 ：hq
 * 时间 ：2017/8/8 14:20
 */
public class NewsFrg extends BaseCommFrg {

    //未登录
    @BindView(R.id.id_no_login_linear)
    LinearLayout mLinearNoLogin;
    //已登录
    @BindView(R.id.id_had_login_linear)
    LinearLayout mLinearHadLogin;


    @Override
    public View loadView(LayoutInflater inflater, View childView) {
        return super.loadView(inflater, inflater.inflate(R.layout.frg_news, null, false));
    }

    @Override
    public void initView() {
        EventBus.getDefault().register(this);
        setUserInfo();
    }

    public void setUserInfo() {
        if (Session.getUserIsLogin()) {
            mLinearNoLogin.setVisibility(View.GONE);
            mLinearHadLogin.setVisibility(View.VISIBLE);
        } else {
            mLinearNoLogin.setVisibility(View.VISIBLE);
            mLinearHadLogin.setVisibility(View.GONE);
        }
    }

    @OnClick({R.id.id_go_login_btn})
    public void onClick(View mView) {
        switch (mView.getId()) {
            //去登录
            case R.id.id_go_login_btn:
                isLogin(false);
                break;
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void eventUpdate(BaseEvent event) {
        String data = event.data;
        if (TextUtils.equals(data, IntentKey.Login.KEY_LOGIN_SUCCESS)) {
            //登录成功
            setUserInfo();
        } else if (TextUtils.equals(data, IntentKey.Login.KEY_APP_EXIT)) {
            //退出登录
            setUserInfo();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

}
